package com.xique.blelock.view.AcountManager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ivin.crop.Log;
import com.ivin.widget.EditTextMaxLength;
import com.xique.blelock.NetUtils.NetResult;
import com.xique.blelock.NetUtils.XqNetClient;
import com.xique.blelock.R;
import com.xique.blelock.Utils.ACache;
import com.xique.blelock.Utils.MyActivityManager;
import com.xique.blelock.Utils.SettingManager;
import com.xique.blelock.Utils.StringUtil;
import com.xique.blelock.Utils.Stringkey;
import com.xique.blelock.Utils.TimeUtil;
import com.xique.blelock.view.BaseActivity;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class Idea_activity extends BaseActivity {
    private ImageView backm;

    @BindView(R.id.rightbutton)
    TextView save;



    @BindView(R.id.title)
    TextView title;

    @BindView(R.id.et_advice)
    EditTextMaxLength editTextMaxLength;

    @BindView(R.id.postmail)
    EditText postmail;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yijainfankun);
        ButterKnife.bind(this);
        initview();
    }

    private void initview() {
        save.setVisibility(View.VISIBLE);
        save.setText("提交");
        save.setTextColor(getResources().getColor(R.color.primary));
        title.setText("意见反馈");

    }

    @OnClick(R.id.rightbutton)
    public void submit(){
        if(TextUtils.isEmpty(editTextMaxLength.getText())){
            showToast(this, "请输入反馈内容");
            return;
        }
//        if(TextUtils.isEmpty(postmail.getText()) ||  (!StringUtil.isEmail(postmail.getText().toString()))){
//            showToast(this, "请输入邮箱");
//        }

        XqNetClient netClient =  new XqNetClient();
        JSONObject jsonobject = new JSONObject();
        try {
            jsonobject.put("token", userInfo.getToken());
            jsonobject.put("uid", userInfo.getUid());
            jsonobject.put(Stringkey.Content, editTextMaxLength.getText().toString());
            if(!TextUtils.isEmpty(postmail.getText())){
                jsonobject.put(Stringkey.PostMail, postmail.getText().toString());
            }else{
                jsonobject.put(Stringkey.PostMail, "");
            }
            jsonobject.put("timestamp", TimeUtil.getSystemCurrentTimeLong()+"");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        showProgressDialog();
        netClient.sendSuggestiions(jsonobject.toString()).enqueue(new Callback<NetResult>() {
            @Override
            public void onResponse(Call<NetResult> call, Response<NetResult> response) {
                hideProgressDialog();
                Log.e("反馈返回的内容是："+ com.alibaba.fastjson.JSONObject.toJSONString(response), "");
                    if(response.body()!=null && response.body().isSuccess()){
                        showToast(Idea_activity.this, "反馈成功");
                        finish();
                    }else{
                        showToast(Idea_activity.this, "反馈失败"+response.message());
                    }

            }

            @Override
            public void onFailure(Call<NetResult> call, Throwable t) {
                hideProgressDialog();
                t.printStackTrace();
            }
        });
    }




    @OnClick(R.id.BACKER)
    public void BackLastPage(){
        finish();
    }
}
